package com.cnhis.cloudhealth.clinical.hosdoctor.doctorordernew.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.cnhis.cloudhealth.clinical.hosdoctor.doctorordernew.bo.DoctorordernewBo;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.util.PinYinUtilForLucence;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;
import com.cnhis.cloudhealth.commons.utils.jpinyin.PinyinHelper;
import com.cnhis.cloudhealth.commons.utils.sorl.BaseSolr;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by xiezhenyuan on 2016/3/25.
 */
@Service
public class DoctorordernewImpl implements IDoctorordernew {

    @Autowired
    private DoctorordernewBo doctorordernewBo;

    @Override
    public ModelVo getPhaveoutorder(Map map) {
        return doctorordernewBo.selectPhaveoutorder(map);
    }

    @Override
    public ModelVo getPfeealert(Map map) {
        return doctorordernewBo.selectPfeealert(map);
    }

    @Override
    public ModelVo getLastmedhistory(Map map) {
        return doctorordernewBo.selectLastmedhistory(map);
    }

    @Override
    public ModelVo getPdrugallergyrcd(Map map) {
        return doctorordernewBo.selectPdrugallergyrcd(map);
    }

    @Override
    public ModelVo getPisallergy(Map map) {
        return doctorordernewBo.selectPisallergy(map);
    }
    @Override
    public ModelVo clinicDrugJudge(Map map) throws Exception {
        return doctorordernewBo.clinicDrugJudge(map);
    }

    @Override
    public ModelVo getDrugfeedetail() {
        return doctorordernewBo.selectDrugfeedetail();
    }

    @Override
    public ModelVo insertQuickOrder(Map map) throws Exception{
        return doctorordernewBo.insertQuickOrder(map);
    }

    @Override
    public ModelVo getPisvip(Map map) {
        return doctorordernewBo.selectPisvip(map);
    }

    @Override
    public ModelVo insertClinicVAF2(Map map) throws Exception{
        return doctorordernewBo.insertClinicVAF2(map);
    }

    @Override
    public ModelVo getMedOrderca(Map map) throws Exception {
        return doctorordernewBo.selectMedOrderca(map);
    }

    @Override
    public ModelVo getMedOrderrecid(Map map) throws Exception{
        return doctorordernewBo.selectMedOrderrecid(map);
    }

    @Override
    public ModelVo getOrdervaluation(Map map) {
        return doctorordernewBo.selectOrdervaluation(map);
    }

    @Override
    public ModelVo getOrderlistvaluation(Map map) {
        return doctorordernewBo.selectOrderlistvaluation(map);
    }

    @Override
    public ModelVo getOrderlistvaluation2(Map map) {
        return doctorordernewBo.selectOrderlistvaluation2(map);
    }

    @Override
    public ModelVo getOrderitemfee(Map map) {
        return doctorordernewBo.selectOrderitemfee(map);
    }

    @Override
    public ModelVo getOrderexerecord(Map map) {
        return doctorordernewBo.selectOrderexerecord(map);
    }

    @Override
    public ModelVo getOrdersummary(Map map) {
        return doctorordernewBo.selectOrdersummary(map);
    }

    @Override
    public ModelVo getTempOrdervaluation(Map map) {
        return doctorordernewBo.selectTempOrdervaluation(map);
    }

    @Override
    public ModelVo getOperationcrew(Map map) {
        return doctorordernewBo.selectOperationcrew(map);
    }

    @Override
    public ModelVo getOperationvaludation(Map map) {
        return doctorordernewBo.selectOperationvaludation(map);
    }

    @Override
    public ModelVo getOperationsendrcd(Map map) {
        return doctorordernewBo.selectOperationsendrcd(map);
    }

    @Override
    public ModelVo getOrderitemfee2(Map map) {
        return doctorordernewBo.selectOrderitemfee2(map);
    }


    @Override
    public ModelVo getDiagnosticrecords(Map map) {
        return doctorordernewBo.selectDiagnosticrecords(map);
    }

    @Override
    public ModelVo getDiseaseType() {
        return doctorordernewBo.selectDiseaseType();
    }
    @Override
    public ModelVo getDiseaseDir(Map map) {
        return doctorordernewBo.selectDiseaseDir(map);
    }

    @Override
    public ModelVo getDiagroottype() {
        return doctorordernewBo.selectDiagroottype();
    }

    @Override
    public ModelVo getOrderitems(Map map) {
        return doctorordernewBo.selectOrderitems(map);
    }

    /**
     * 725 树形：按药品规格 检索品种分类对应的明细项目
     */
    public ModelVo medTreeToDetail(Map map, int currentPage, int pageSize)
            throws Exception
    {
        return doctorordernewBo.medTreeToDetail(map, currentPage, pageSize);
    }

    @Override
    public ModelVo getTreatItems(Map map,int currentPage, int pageSize) {
        return doctorordernewBo.selectTreatItems(map,currentPage,pageSize);
    }

    @Override
    public ModelVo getDrupguige(Map map) {
        return doctorordernewBo.selectDrupguige(map);
    }

    @Override
    public ModelVo getDrupway(Map map) {
        return doctorordernewBo.selectDrupway(map);
    }

    @Override
    public ModelVo getOperationpro(Map map,int pageno,int pagesize) {
        return doctorordernewBo.selectOperationpro(map,pageno,pagesize);
    }

    @Override
    public ModelVo getAnaesthesiaItem() {
        return doctorordernewBo.selectAnaesthesiaItem();
    }

    @Override
    public ModelVo getSampletype() {
        return doctorordernewBo.selectSampletype();
    }

    @Override
    public ModelVo getFootnote() {
        return doctorordernewBo.selectFootnote();
    }

    @Override
    public ModelVo getDrugcompro(Map map) {
        return doctorordernewBo.selectDrugcompro(map);
    }

    @Override
    public ModelVo getFriedtype() {
        return doctorordernewBo.selectFriedtype();
    }

    @Override
    public ModelVo getJijia(Map map) throws Exception{
        return doctorordernewBo.selectJijia(map);
    }

    @Override
    public ModelVo getJijia2(Map map) throws Exception {
        return doctorordernewBo.selectJijia2(map);
    }

    @Override
    public ModelVo getJijia3(Map map) throws Exception {
        return doctorordernewBo.selectJijia3(map);
    }

    @Override
    public ModelVo getExefreq(Map map) {
        return doctorordernewBo.selectExefreq(map);
    }

    @Override
    public ModelVo getExebck(Map map) throws Exception{
        return doctorordernewBo.selectExebck(map);
    }
    @Override
    public ModelVo getPishi(Map map) throws Exception{
        return doctorordernewBo.getPishi(map);
    }
    @Override
    public ModelVo getDrupbck(Map map) {
        return doctorordernewBo.selectDrupbck(map);
    }

    @Override
    public ModelVo getTreatList(Map map) {
        return doctorordernewBo.selectTreatList(map);
    }

    @Override
    public ModelVo getYishi(Map map) {
        return doctorordernewBo.selectYishi(map);
    }

    @Override
    public ModelVo getCnExeBck(Map map) throws Exception{
       return doctorordernewBo.selectCnExeBck(map);
    }

    @Override
    public ModelVo checkDepHasOpera(Map map) {
        return doctorordernewBo.checkDepHasOpera(map);
    }

    @Override
    public ModelVo getShoushujijia(Map map) {
        return doctorordernewBo.selectShoushujijia(map);
    }

    @Override
    public ModelVo getJianchajijia(Map map) {
        return doctorordernewBo.selectJianchajijia(map);
    }

    @Override
    public ModelVo getSendDrugvaluation(Map map) {
        return doctorordernewBo.selectSendDrugvaluation(map);
    }

    @Override
    public ModelVo getDrugDest() {
        return doctorordernewBo.selectDrugDest();
    }

    @Override
    public ModelVo getOprationRank() {
        return doctorordernewBo.selectOprationRank();
    }

    @Override
    public ModelVo getSendedCNDrugvaluation(Map map) {
        return doctorordernewBo.selectSendedCNDrugvaluation(map);
    }

    @Override
    public ModelVo getHygiMaterBck(Map map) throws Exception {
        return doctorordernewBo.selectHygiMaterBck(map);
    }

    @Override
    public ModelVo getWeishengJijia(Map map) {
        return doctorordernewBo.selectWeishengJijia(map);
    }
    @Override
    public Map selectsolrlist(Integer bck01,Integer corporationid,String dbname,Integer type) throws Exception {
        return doctorordernewBo.selectsolrlist(bck01,corporationid,dbname,type);
    }
    public ModelVo queryAdviceBySolr(Map map)throws Exception{
    	 ModelVo mv = new ModelVo();  
    	 try
         {
             List<Map<String, Object>> list = BaseSolr.querySolr(map.get("url").toString(), map);
             mv.setList(list);
             mv.setResult(StaticKeys.OH_SUCCESS);
         }
         catch (Exception e)
         {
             mv.setResult(StaticKeys.OH_FALSE);
             e.printStackTrace();
         }
         return mv;
    };
    
    public ModelVo zhuyuanbatchAddDoc(String url,Integer bck01,Integer corporationid,String dbname,Integer type)throws Exception{
	    ModelVo mv = new ModelVo();  	    
	    try
	    {
	    	Map mylist = selectsolrlist(bck01,corporationid,dbname,type);
	    	List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	        list.addAll((List<Map<String, Object>>)mylist.get("listM"));
	        list.addAll((List<Map<String, Object>>) mylist.get("listT"));
	        
	        for (Map<String, Object> map : list)
	        {
	            map.put("szm", PinyinHelper.getShortPinyin(map.get("bbx05").toString()));
	        }
	        if(type==2){
	        	if(dbname.equals("")){
	        		BaseSolr.deleteDocumentByQuery(url+"/zhuyuanyizhu", "(bda01:\"4\" OR bda01:\"7\" OR bda01:\"8\" bda01:\"9\" OR bda01:\"A\" OR bda01:\"B\" OR "
		        			+ "bda01:\"D\" OR bda01:\"E\" OR bda01:\"L\" OR bda01:\"N\" OR bda01:\"O\" OR bda01:\"P\" OR bda01:\"S\" OR bda01:\"T\" OR bda01:\"Z\" OR bda01:\"M\") AND corporationid:\"\\" + corporationid + "\" AND bck01:\""+ bck01+"\"");
	        	}else{
	        		BaseSolr.deleteDocumentByQuery(url+"/zhuyuanyizhu", "(bda01:\"4\" OR bda01:\"7\" OR bda01:\"8\" bda01:\"9\" OR bda01:\"A\" OR bda01:\"B\" OR "
		        			+ "bda01:\"D\" OR bda01:\"E\" OR bda01:\"L\" OR bda01:\"N\" OR bda01:\"O\" OR bda01:\"P\" OR bda01:\"S\" OR bda01:\"T\" OR bda01:\"Z\" OR bda01:\"M\") AND corporationid:\"\\" + corporationid + "\" AND bck01:\""+ bck01+"\" AND dbname:\""+ dbname+"\"");
	        	}
	        	
	       	
	        }else{
	        	if(dbname.equals("")){
	        		BaseSolr.deleteDocumentByQuery(url+"/zhuyuanyizhu", "(bda01:\"4\" OR bda01:\"1\" OR bda01:\"2\" OR bda01:\"3\" OR bda01:\"M\") AND corporationid:\"\\" + corporationid + "\" AND bck01:\""+ bck01+"\"");
	        	}else{
	        		BaseSolr.deleteDocumentByQuery(url+"/zhuyuanyizhu", "(bda01:\"4\" OR bda01:\"1\" OR bda01:\"2\" OR bda01:\"3\" OR bda01:\"M\") AND corporationid:\"\\" + corporationid + "\" AND bck01:\""+ bck01+"\" AND dbname:\""+ dbname+"\"");
	        	}
	        	
	        }
	        
	        BaseSolr.batchAddDoc(url+"/zhuyuanyizhu",list);
	
	        mv.setResult(StaticKeys.OH_SUCCESS);
	    }
	    catch (Exception e)
	    {
	        mv.setResult(StaticKeys.OH_FALSE);
	        e.printStackTrace();
	    }
	    return mv;
    }

	@Override
	public ModelVo delete6433(Map map) throws Exception {
		// TODO Auto-generated method stub
		return doctorordernewBo.delete6433(map);
	}

	@Override
	public ModelVo update6433(Map map) throws Exception {
		// TODO Auto-generated method stub
		return doctorordernewBo.update6433(map);
	}

    @Override
    public ModelVo NurseSetVCL1VCL17(Map map) throws Exception{
        return doctorordernewBo.NurseSetVCL1VCL17(map);
    }
}
